package cn.edu.swufe.surverpark.struts2.action;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.edu.swufe.surverpark.model.User;
import cn.edu.swufe.surverpark.struts2.service.RightService;
import cn.edu.swufe.surverpark.struts2.service.UserService;
import cn.edu.swufe.surverpark.util.DataUtil;

/**
 *@author 陈龙 E-mail:529914446@qq.com
 *@version创建时间:2015年4月29日下午10:58:28
 *登陆action
 */
@Controller
@Scope("prototype")
public class LoginAction extends BaseAction<User> 
	implements SessionAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Resource
	private UserService userService;
	@Resource
	private RightService rightService;
	public String toLoginPage(){
		return "loginPage";
	}
	/**
	 * 进行登陆处理
	 * @return
	 */
	public String doLogin(){
		
		return "success";
	}
	/**
	 * 校验登陆信息
	 */
	public void validateDoLogin() {
		User user = userService.validateLoginInfo(model.getEmail(),DataUtil.md5(model.getPassword()));
		if(user == null){
			addActionError("email/password错误");
		}else{
			
			int maxPos = rightService.getMaxRightPos();
			user.setRightSum(new long[maxPos + 1]);
			user.calculateRightSum();
			session.put("user", user);
		}
	}
	private Map<String,Object> session;
	@Override
	public void setSession(Map<String, Object> arg0) {
		this.session = arg0;
		
	}
	


}

